public class ThreadDemo12 {
    private static boolean isQuit = false;
    public static void main(String[] args){
        Thread t = new Thread(() ->{
           while (!isQuit){
               System.out.println("该线程正在工作！");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           }
            System.out.println("该线程工作完毕！");
        });
        t.start();

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("该线程即将结束！");
        isQuit = true;
    }
}
